
<script>
export default {
  data() {
    return {
      tableData: [        // 重复的项目数据可以通过后端接口获取后填充在这里
      ],
      form:{},
      total:0,
      current:1,
      pageSize:5,
      dialogVisible: false,
      xmgl:{},
      ids:[],
    };
  },
  methods: {
    handleSelectionChange(val){
      this.ids = val
    },
    handleDelete(id) {
      this.$confirm('此操作将永久删除该数据，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 这里是用户点击确定后执行的代码，例如发送删除请求到后端
        this.axios.get(`http://localhost:8302/xiangmu/del?id=${id}`).then(res=>{
          this.findAll();
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
      }).catch(() => {
        // 这里是用户点击取消后执行的代码，通常不需要做什么特别的事情
      });
    },
    doUpdate(id){
      this.axios.get(`http://localhost:8302/xiangmu/queryById?id=${id}`).then(res=>{
          this.xmgl=res.data.data;
          this.dialogVisible = true;
      })
    },
    saveData(){
      this.axios.post(`http://localhost:8302/xiangmu/save`,this.xmgl).then(res=>{
        this.dialogVisible = false;
        this.xmgl={}
        this.findAll();
        this.$message({
          type: 'success',
          message: '保存成功!'
        });
      })
    },
    fh(){
      this.xmgl={}
    },
    openDialog() {
      this.dialogVisible = true;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.findAll();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.current = val;
      this.findAll();
    },
    findAll(){
      this.axios.post(`http://localhost:8302/xiangmu/getAll?current=${this.current}&pageSize=${this.pageSize}`,this.form).then(res=>{
        this.tableData = res.data.data.records;
        this.total = res.data.data.total;
      })
    },
    // tiao(){
    //   this.$router.push('/')
    // },
  },
  created() {
    this.findAll()
  }
};
</script>
<template>
  <div align="left" class="c">
    <router-view/>
      <el-container>
        <el-header  style="margin-top: 60px"> |  服务项目管理</el-header>
        <el-main>
          <el-row>
            <el-col style="background-color: #F2F7FB" :span="3">
              <el-select v-model="form.xmlx" placeholder="请选择项目类型">
                <!-- 这里可以根据实际情况添加项目类型选项 -->
                <el-option label="全部" :value="null"></el-option>
                <el-option label="免费项目" value="免费项目"></el-option>
                <el-option label="付费项目" value="付费项目"></el-option>
              </el-select>
            </el-col>
            <el-col style="background-color: #F2F7FB" :span="3">
              <el-input v-model="form.name" placeholder="请输入关键字"></el-input>
            </el-col>
            <el-col style="background-color: #F2F7FB" :span="3">
            <el-button type="primary" style="width: 80px;" @click="findAll">查询</el-button>
            </el-col>
            <el-col style="background-color: #F2F7FB" :span="13" align="right">
              <el-button type="primary" style="width: 120px" @click="openDialog">新增服务项目</el-button>
            </el-col>
          </el-row>
          <el-table
            :data="tableData"
            border
            @selection-change="handleSelectionChange"
            style="width: 100%">
          <el-table-column
              type="selection"
              width="55">
          </el-table-column>
          <el-table-column
              prop="id"
              label="项目编号">
          </el-table-column>
          <el-table-column
              prop="name"
              label="项目名称">
          </el-table-column>
          <el-table-column
              label="次数">
            <template slot-scope="scope">
              {{ scope.row.num }} 次
            </template>
          </el-table-column>
          <el-table-column
              prop="xmlx"
              label="项目类型">
<!--            <template slot-scope="scope">-->
<!--              {{ scope.row.sex == 0 ? '男' : '女' }}-->
<!--            </template>-->
          </el-table-column>
          <el-table-column
              prop="xmjs"
              label="项目介绍">
          </el-table-column>
<!--          <el-table-column-->
<!--              prop="birthday"-->
<!--              label="生日">-->
<!--          </el-table-column>-->
<!--          <el-table-column-->
<!--              prop="rname"-->
<!--              label="宿舍号">-->
<!--          </el-table-column>-->

          <el-table-column
              label="操作">
            <template slot-scope="scope">
              <el-button type="primary" style="width: 80px;" @click="doUpdate(scope.row.id)">编辑</el-button>
              <el-button type="primary" style="width: 80px;" @click="handleDelete(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

          <template>
            <el-dialog :visible.sync="dialogVisible" title="新增服务项目" >
              <el-form :model="xmgl" ref="form" label-width="120px">
                <el-form-item label="项目名称*" :rules="[{ required: true, message: '请输入项目名称' }]">
                  <el-input v-model="xmgl.name" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="项目类型" :rules="[{ required: true, message: '请选择项目类型' }]">
                  <el-select v-model="xmgl.xmlx" placeholder="请选择">
                    <el-option label="免费项目" value="免费项目"></el-option>
                    <el-option label="付费项目" value="付费项目"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="服务次数*" :rules="[{ required: true, message: '请输入服务次数' }]">
                  <el-input v-model="xmgl.num" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="项目原价*" :rules="[{ required: true, message: '请输入项目原价' }]">
                  <el-input v-model="xmgl.price" type="number" placeholder="请输入元"></el-input>
                </el-form-item>
                <el-form-item label="服务介绍" :rules="[{ required: true, message: '请输入服务介绍' }]">
                  <el-input v-model="xmgl.xmjs" type="number" placeholder="请输入"></el-input>
                </el-form-item>
<!--                <el-form-item>-->
<!--                  <el-button type="primary" @click="onSubmit">立即创建</el-button>-->
<!--                  <el-button>取消</el-button>-->
<!--                </el-form-item>-->
              </el-form>

              <span slot="footer" class="dialog-footer">
      <el-button style="width: 100px;" @click="dialogVisible = false;fh()">返回</el-button>
      <el-button style="width: 100px;" type="primary" @click="saveData">保存</el-button>
    </span>
            </el-dialog>
          </template>
        </el-main>


        <el-pagination
            background
            layout="prev, pager, next"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="current"
            :page-size="pageSize">
        </el-pagination>


      </el-container>
  </div>
</template>

<style >
.c{
  background-color: #F2F7FB;
  border: 1px solid #d3dce6;
  border-radius: 5px;
  padding: 10px;
  margin: 10px;
  width: 90%;
  height: 90%;
  overflow: auto;
}
</style>



